package com.yunfei.api.financialCalculator.service;
import com.yunfei.api.financialCalculator.param.GuDingShouYiLeiCalParam;
import com.yunfei.api.financialCalculator.result.GuDingShouYiLeiCalResult;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.enums.GuDingShouYiCalResultStatus;
import com.yunfei.enums.ResultStatus;
import com.yunfei.procedure.GuDingShouYiCalProcedure;
import com.yunfei.utils.jdbc.AiiidbUtil;
import com.yunfei.utils.string.StringUtil;
import org.springframework.core.env.Environment;

public class GuDingShouYiLeiCalService {
    //统计计算器接口
    public static ResultModel cal(GuDingShouYiLeiCalParam param, Environment env){
        ResultModel resultModel=new ResultModel();
        String buyAmt=param.getBuyAmt();
        String daysCnt=param.getDaysCnt();
        String rae=param.getRae();
        //参数校验
        if(StringUtil.isNullOrEmpty(buyAmt)){
            resultModel.setCode(GuDingShouYiCalResultStatus.buyAmt.getCode());
            resultModel.setMessage(GuDingShouYiCalResultStatus.buyAmt.getMessage());
            return resultModel;
        }
        if(StringUtil.isNullOrEmpty(daysCnt)){
            resultModel.setCode(GuDingShouYiCalResultStatus.daysCnt.getCode());
            resultModel.setMessage(GuDingShouYiCalResultStatus.daysCnt.getMessage());
            return resultModel;
        }
        if(StringUtil.isNullOrEmpty(rae)){
            resultModel.setCode(GuDingShouYiCalResultStatus.rae.getCode());
            resultModel.setMessage(GuDingShouYiCalResultStatus.rae.getMessage());
            return resultModel;
        }
        //获取数据库连接
        AiiidbUtil aiiidbUtil=AiiidbUtil.getInstance(env);
        //调用处处过程
        GuDingShouYiLeiCalResult result=new GuDingShouYiCalProcedure().callProcedure(aiiidbUtil,param);
        resultModel.setData(result);
        resultModel.setCode(ResultStatus.SUCCESS.getCode());
        resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        return resultModel;
    }
}
